import requestMeeting, { request } from '@/plugins/axios'
import { PollEntity, PollPlanResponseEntity } from './interface'
/**
 *
 * @param meeting_id 会议的meetingMoid
 * @param type 轮询类型 1 会议轮询 2 管理方轮询 3 上传轮询
 * @returns 获取轮询信息(对应8.0接口:)
 */
export const fetchGetPollInfo = async (meeting_id: string, type: number) =>
	requestMeeting<PollEntity>({
		url: `/mcc/${meeting_id}/poll/${type}`,
		method: 'GET',
	}).then((res) => res)
/**
 *
 * @param meeting_id 会议的meetingMoid
 * @returns 检测开始轮询  仅对于 0 会议轮询 1 管理方轮询
 */
export const fetchStartMeetingPollAndMangerPollCheck = async (meeting_id: string) =>
	requestMeeting<{
		/**点名轮询是否开启 */
		roll_is_on: 0 | 1
		/**管理方轮询是否开启 */
		poll_ma_is_on: 0 | 1
		/**轮询是否开启 */
		poll_is_on: 0 | 1
	}>({
		url: `/mcc/${meeting_id}/poll/check`,
		method: 'GET',
	}).then((res) => res)
/**
 *
 * @param meeting_id 会议的meetingMoid
 * @param type 轮询类型 1-会议轮询; 2-管理方轮询; 3-上传轮询
 * @returns 返回改变轮询状态是否成功
 */
export const fetchStartPoll = async (meeting_id: string, type: number, poll: any) =>
	requestMeeting({
		url: `/mcc/${meeting_id}/poll/${type}`,
		method: 'POST',
		data: poll,
	}).then((res) => res.success)
/**
 * 停止所有轮询(特指停止停止点名轮询)
 * @param meeting_id 会议的meetingMoid
 * @returns 停止所有轮询 (不包括上传轮询)
 */
export const fetchStopRollCall = async (meeting_id: string) =>
	requestMeeting({
		url: `/mcc/${meeting_id}/poll/all`,
		method: 'DELETE',
		data: {},
	}).then((res) => res.success)
/**
 * 暂停轮询 、停止轮询 、 继续轮询
 * @param meeting_id 会议的meetingMoid
 * @param type 轮询类型 1-会议轮询; 2-管理方轮询; 3-上传轮询
 * @param state 轮询状态 0-停止轮询;1-暂停轮询;2-继续轮询;
 * @returns 返回改变轮询状态是否成功
 */
export const fetchUpdatePollState = async (meeting_id: string, type: number, state: number) =>
	requestMeeting({
		url: `/mcc/${meeting_id}/poll/state`,
		method: 'PUT',
		data: { type: type, state: state },
	}).then((res) => res.success)
/**
 *
 * @param meeting_id meeting_id 会议的meetingMoid
 * @param type type 轮询类型
 * @param poll poll 轮询数据
 * @returns 返回改变参数是否成功
 */
export const fetchChangePollInfo = async (meeting_id: string, type: number, poll: any) =>
	requestMeeting({
		url: `/mcc/${meeting_id}/poll/${type}`,
		method: 'PUT',
		data: poll,
	}).then((res) => res)
/**
 *
 * @param meetingMoid
 * @returns 获取预案列表数据
 */
export const fetchGetPollPlanList = async (meetingMoid: string) =>
	requestMeeting<PollPlanResponseEntity>({
		url: `/meetings/${meetingMoid}/prepolls?count=0`,
		method: 'GET',
	}).then((res) => res)
/**
 *
 * @param meetingMoid 会议的meetingMoid
 * @param value 预案的id
 * @returns  获取预案详情
 */
export const fetchGetPollPlanDetail = async (meetingMoid: string, value: string) =>
	request<PollEntity>({
		url: `/meetings/${meetingMoid}/prepolls/${value}?type=1`,
		method: 'GET',
	}).then((res) => res)
/**
 *
 * @param meetingMoid 会议的meetingMoid
 * @param value 预案名称
 * @returns 删除预案
 */
export const fetchDeletePollPlan = async (meetingMoid: string, value: string) =>
	requestMeeting({
		url: `/meetings/${meetingMoid}/prepolls/${value}`,
		method: 'DELETE',
	}).then((res) => res)
/**
 *
 * @param meetingMoid 会议的meetingMoid
 * @param value 预案名称
 * @returns 新增预案
 */
export const fetchAddPollPlan = async (meetingMoid: string, plan_data: any) =>
	requestMeeting({
		url: `/meetings/${meetingMoid}/prepolls`,
		method: 'POST',
		data: JSON.stringify(plan_data),
	}).then((res) => res)
/**
 *
 * @param meetingMoid 会议的meetingMoid
 * @param value 预案名称
 * @returns 更新预案
 */
export const fetchUpdatePollPlan = async (meetingMoid: string, id: string, plan_data: any) =>
	requestMeeting({
		url: `/meetings/${meetingMoid}/prepolls/${id}`,
		method: 'POST',
		data: JSON.stringify(plan_data),
	}).then((res) => res)
